package com.yourcompany.api.builder;

import com.yourcompany.api.entity.LoginLog;
import com.yourcompany.common.utils.WebUtils;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

// 登录日志构造器

@Data
@Builder
public class LoginLogBuilder {
    private String username;
    private Long userId;
    private String loginType;
    private String deviceId;
    private String userAgent;
    private Integer status;
    private String msg;

    // 构造方法
    public LoginLog build() {
        LoginLog loginLog = new LoginLog();
        loginLog.setUserId(userId);
        loginLog.setUsername(username);
        loginLog.setLoginType(loginType);
        loginLog.setDeviceId(deviceId);
        loginLog.setUserAgent(userAgent != null ? userAgent : WebUtils.getUserAgent());
        loginLog.setLoginIp(WebUtils.getIpAddr());
        loginLog.setLoginLocation(WebUtils.getLocationByIp(loginLog.getLoginIp()));
        loginLog.setLoginTime(LocalDateTime.now());
        loginLog.setStatus(status);
        loginLog.setMsg(msg);
        return loginLog;
    }
} 